package com.jiantong.work.impl.service;

import com.google.common.base.Throwables;
import com.jiantong.work.impl.dao.DisinfectReportDao;
import com.jiantong.work.impl.manager.DisinfectReportManager;
import com.jiantong.work.model.DisinfectReport;
import com.jiantong.work.service.DisinfectReportWriteService;
import io.terminus.boot.rpc.common.annotation.RpcProvider;
import io.terminus.common.model.Response;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.util.Map;

/**
 * Created by maowenjie on 2017/3/29.
 */
@Slf4j
@Service
@RpcProvider
public class DisinfectReportWriteServiceImpl implements DisinfectReportWriteService{
    public final DisinfectReportDao disinfectReportDao;
    public final DisinfectReportManager disinfectReportManager;

    public DisinfectReportWriteServiceImpl(DisinfectReportDao disinfectReportDao, DisinfectReportManager disinfectReportManager) {
        this.disinfectReportDao = disinfectReportDao;
        this.disinfectReportManager = disinfectReportManager;
    }

    @Override
    public Response<Map<String,Object>> create(DisinfectReport disinfectReport,Integer toStatus) {
        try {
            return Response.ok(disinfectReportManager.createDisinfectReportManager(disinfectReport,toStatus));
        } catch (Exception e) {
            log.error("failed to create disinfectReport  error :{}", Throwables.getStackTraceAsString(e));
            return Response.fail("create.disinfectReport");
        }
    }
    @Override
    public Response<Map<String,Object>> update(DisinfectReport disinfectReport,Integer toStatus) {
        try{
            return Response.ok(disinfectReportManager.updateDisinfectReportManager(disinfectReport,toStatus));
        }catch (Exception e){
            log.error("failed to update disinfectReport  error:{}", Throwables.getStackTraceAsString(e));
            return Response.fail("update.disinfectReport");
        }
    }

    @Override
    public Boolean update(DisinfectReport disinfectReport) {
        return disinfectReportDao.update(disinfectReport);
    }
}
